<?php

namespace console\controllers;

use Yii;
use services\baibai\DataMigrateService;
use services\baibai\UpdateDataMigrateService;
use yii\console\Controller;
use Exception;

/**
 * 迁移白白管家数据
 *
 * Class BaibaiDataMigrateController
 * @package console\controllers
 */
class BaibaiDataMigrateController extends Controller
{
    /**
     * 数据迁移
     */
    public function actionCreateBaibai()
    {
        try {
            $startTime = time();
            DataMigrateService::allData();
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    /**
     * 数据更新
     */
    public function actionUpdateBaibai($start, $end)
    {
        try {
            $startTime = time();

            $params['start_time'] = isset($start) && $start ? strtotime($start) : (strtotime(date('Y-m-d', time())) - 2*86400);
            $params['end_time'] = isset($end) && $end ? (strtotime($end) + 86399) : (strtotime(date('Y-m-d', time() + 86400)) - 1);

            UpdateDataMigrateService::allData(['start_time' => $params['start_time'], 'end_time' => $params['end_time']]);
            echo '时间' . (time() - $startTime) . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }
}
